package com.zrrd.learn.chapter06;

import java.util.Arrays;

/**
 * 数组小题
 *
 * @author asus
 * @version 1.0
 * @date 2023/7/14 14:03
 */
public class ArrayWork04 {
//    定义一个数组来存储12个学生的成绩{72,89,65,58,87,91,53,82,71,93,76,68}，计算并输出学生的平均成绩。(保留小数点后两位。)

    public static void question01(double[] arr1){
        double average=0;
        double sum=0;
        for (int i = 0; i < arr1.length; i++) {
            sum+=arr1[i];
            average=sum/ arr1.length;
        }
        //保留两位小数
        String  str22 = String.format("%.2f",average);
        double average22= Double.parseDouble(str22);
        //输出
        System.out.println("平均数为："+average22);
    }
//    统计数组{20,45,78,34,16,3,99,56}中大于50的有多少个、小于50的有多少个并打印输出。

    public static void question02(int[] arr2){
         int small=0;
        int big=0;
        Arrays.sort(arr2);
        System.out.println(Arrays.toString(arr2));

        for (int i = 0; i < arr2.length; i++) {
                if(arr2[i]<50) {
                    System.out.println("小于50的数有："+arr2[i]);
                    small++;
                }else if(arr2[i]>50){
                    System.out.println("大于50的数有："+arr2[i]);
                    big++;
            }
        }
        System.out.println("小于50的数有"+small+"个");
        System.out.println("大于50的数有"+(big)+"个");

    }



    public static void main(String[] args) {
        double[] a={72,89,65,58,87,91,53,82,71,93,76,68};
        int[] b={20,45,78,34,16,3,99,56};
//        question01(a);
        question02(b);
    }
}
